package com.Jhu1.mapper;

import com.Jhu1.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 用户�? Mapper 接口
 * </p>
 *
 * @author 钟俊辉
 * @since 2025-01-14
 */
public interface UserMapper extends BaseMapper<User> {
    @Select("""
            select * from user
            where user_name = #{userName}
            """)
    User findByuserName(String userName);

    @Insert("""
            insert into user(user_name,user_password,role,create_time,update_time)
            values(#{userName},#{password},#{role},now(),now())
            """)
    void register(String userName, String password, String role);

    @Update("""
            update user
            set user_avatar=#{userAvatar},user_nickname=#{userNickname},user_email=#{userEmail},update_time=now()
            where id=#{id}
            """)
    void update(User user);

    @Update("""
            update user
            set user_avatar=#{url},update_time=now()
            where id=#{id}
            """)
    void updateAvatar(Integer id, String url);

    @Update("""
            update user
            set user_password=#{newPwd},update_time=now()
            where id=#{id}
            """)
    void updatePwd(Integer id, String newPwd);
}
